home *** CD-ROM | disk | FTP | other *** search
/ Champak 114 / Vol 114.iso / games / park_thi.swf / scripts / DefineSprite_803 / frame_1 / DoAction.as < prev   
Encoding:
Text File  |  2010-08-12  |  11.1 KB  |  347 lines

  1. function checkCollision(mc2, mc1, tolerance, scope)
  2. {
  3.    var _loc1_ = classes.CollisionDetection.checkForCollision(mc1,mc2,255);
  4.    return _loc1_;
  5. }
  6. function adjust(v, threshold, maximum)
  7. {
  8.    vx = 0;
  9.    if(v <= threshold)
  10.    {
  11.       vx = v / threshold * 1;
  12.    }
  13.    else
  14.    {
  15.       vx = 1;
  16.    }
  17.    return vx;
  18. }
  19. function move()
  20. {
  21.    this._rotation = angle * 180 / 3.141593;
  22.    UD = Key.isDown(38) - Key.isDown(40);
  23.    if(!hit)
  24.    {
  25.       LR = Key.isDown(39) - Key.isDown(37);
  26.    }
  27.    HAND = Key.isDown(32);
  28.    if(LR && !hit)
  29.    {
  30.       angle += LR * UD * steer * adjust(Math.abs(speed),steer_threshold,MAXSpd);
  31.    }
  32.    else
  33.    {
  34.       turnskidding = false;
  35.    }
  36.    if(!UD & !hit)
  37.    {
  38.       speed *= drift;
  39.    }
  40.    else if(UD & !HAND & !hit)
  41.    {
  42.       speed = Math.min(Math.max(speed + UD * accel,MINspd),MAXspd);
  43.    }
  44.    if(Math.abs(speed) < accel / 2)
  45.    {
  46.       speed = 0;
  47.    }
  48.    if(HAND)
  49.    {
  50.       speed *= handbrake;
  51.       if(speed > MAXskiddisplay)
  52.       {
  53.          steer = steer_handbrake;
  54.       }
  55.       traction = handbrake_traction / surface;
  56.    }
  57.    else
  58.    {
  59.       skidding = false;
  60.       traction = Math.max(traction_max,Math.abs((speed - MAXturnSpd) / surface));
  61.       steer = steer_normal;
  62.    }
  63.    if(speed <= 0)
  64.    {
  65.       traction = 1;
  66.    }
  67.    if(Key.isDown(32) && isPlayer && spaceUp)
  68.    {
  69.       _parent.valet_mc._x = this._x + 80 * Math.cos((this._rotation - 70) * 3.141592653589793 / 180);
  70.       _parent.valet_mc._y = this._y + 80 * Math.sin((this._rotation - 70) * 3.141592653589793 / 180);
  71.       var _loc4_ = valetCheckB();
  72.       if(_loc4_)
  73.       {
  74.          _root.userCar = "";
  75.          spaceUp = false;
  76.          isPlayer = false;
  77.          _parent.valet_mc.hit = false;
  78.          _parent.valet_mc._visible = true;
  79.       }
  80.    }
  81.    if(!hit)
  82.    {
  83.       this._x += vector[0] += (Math.cos(angle) * speed - vector[0]) / traction;
  84.       this._y += vector[1] += (Math.sin(angle) * speed - vector[1]) / traction;
  85.    }
  86. }
  87. function hitCheck()
  88. {
  89.    if(this.hitTest(_parent[_root.userCar].target_mc) && this._name != _root.userCar)
  90.    {
  91.       if(checkCollision(this,_parent[_root.userCar]) != undefined || checkCollision(this,_parent[_root.userCar]) != null)
  92.       {
  93.          _root.crash_snd.start();
  94.          _parent[_root.userCar].hit = true;
  95.          _parent[_root.userCar].health -= 3;
  96.          allHit();
  97.          this._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
  98.          this._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
  99.          _parent[_root.userCar].speed = (- _parent[_root.userCar].speed) * 1.5;
  100.          _parent[_root.userCar].vector[0] = - _parent[_root.userCar].vector[0];
  101.          _parent[_root.userCar].vector[1] = - _parent[_root.userCar].vector[1];
  102.          _parent[_root.userCar]._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
  103.          _parent[_root.userCar]._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
  104.          _parent[_root.userCar].hit = false;
  105.          if(this.isMovable)
  106.          {
  107.             this.health -= 10;
  108.          }
  109.          else
  110.          {
  111.             this.health -= (15 - this._currentframe) * 5;
  112.          }
  113.          if(this._currentframe == 13)
  114.          {
  115.             _root.cop_mc.gotoAndStop(2);
  116.             var _loc4_ = new Sound();
  117.             var _loc6_ = "snd" + _currentframe;
  118.             _loc4_.attachSound(_loc6_);
  119.             _loc4_.start();
  120.          }
  121.          if(this._currentframe > 13)
  122.          {
  123.             var _loc5_ = _parent.attachMovie("clip" + _currentframe,"man" + _currentframe,_parent.getNextHighestDepth());
  124.             _loc4_ = new Sound();
  125.             _loc6_ = "snd" + _currentframe;
  126.             _loc4_.attachSound(_loc6_);
  127.             _loc4_.start();
  128.             _loc5_._x = this._x;
  129.             _loc5_._y = this._y;
  130.             this.health = 0;
  131.          }
  132.       }
  133.    }
  134. }
  135. function valetCheck()
  136. {
  137.    if(this.hitTest(_parent.valet_mc.hit_mc))
  138.    {
  139.       if(checkCollision(this,_parent.valet_mc) != undefined || checkCollision(this,_parent.valet_mc) != null)
  140.       {
  141.          _parent.valet_mc.hit = true;
  142.          _parent.valet_mc.hitCar = this._name;
  143.          if(Key.isDown(32) && !isPlayer && spaceUp && _root.userCar == "")
  144.          {
  145.             valetIn();
  146.          }
  147.       }
  148.    }
  149. }
  150. function valetCheckB()
  151. {
  152.    i = 0;
  153.    while(i <= _root.carArray.length)
  154.    {
  155.       if(_parent.valet_mc.hit_mc.hitTest(_root.carArray[i]) && _root.userCar != _root.carArray[i]._name)
  156.       {
  157.          return false;
  158.       }
  159.       i++;
  160.    }
  161.    if(_parent.valet_mc.hit_mc.hitTest(_parent.car1_mc) && _root.userCar != "car1_mc")
  162.    {
  163.       return false;
  164.    }
  165.    if(_parent.valet_mc.hit_mc.hitTest(_parent.car2_mc) && _root.userCar != "car2_mc")
  166.    {
  167.       return false;
  168.    }
  169.    if(_parent.valet_mc.hit_mc.hitTest(_parent.car3_mc) && _root.userCar != "car3_mc")
  170.    {
  171.       return false;
  172.    }
  173.    return true;
  174. }
  175. function allHit()
  176. {
  177.    i = 0;
  178.    while(i <= _root.carArray.length)
  179.    {
  180.       if(this.hitTest(_root.carArray[i]) && _root.userCar != _root.carArray[i]._name)
  181.       {
  182.          if(checkCollision(this,_root.carArray[i]) != undefined || checkCollision(this,_root.carArray[i]) != null)
  183.          {
  184.             trace("hit");
  185.             _root.carArray[i]._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
  186.             _root.carArray[i]._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
  187.          }
  188.       }
  189.       i++;
  190.    }
  191.    if(this.hitTest(_parent.car1_mc) && this._name != "car1_mc" && _root.userCar != "car1_mc")
  192.    {
  193.       if(checkCollision(this,_parent.car1_mc) != undefined || checkCollision(this,_parent.car1_mc) != null)
  194.       {
  195.          trace("hit");
  196.          _parent.car1_mc._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
  197.          _parent.car1_mc._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
  198.       }
  199.    }
  200.    if(this.hitTest(_parent.car2_mc) && this._name != "car2_mc" && _root.userCar != "car2_mc")
  201.    {
  202.       if(checkCollision(this,_parent.car2_mc) != undefined || checkCollision(this,_parent.car2_mc) != null)
  203.       {
  204.          trace("hit");
  205.          _parent.car2_mc._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
  206.          _parent.car2_mc._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
  207.       }
  208.    }
  209.    if(this.hitTest(_parent.car3_mc) && this._name != "car3_mc" && _root.userCar != "car3_mc")
  210.    {
  211.       if(checkCollision(this,_parent.car3_mc) != undefined || checkCollision(this,_parent.car3_mc) != null)
  212.       {
  213.          trace("hit");
  214.          _parent.car3_mc._x += _parent[_root.userCar].vector[0] += (Math.cos(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[0]) / _parent[_root.userCar].traction;
  215.          _parent.car3_mc._y += _parent[_root.userCar].vector[1] += (Math.sin(_parent[_root.userCar].angle) * _parent[_root.userCar].speed - _parent[_root.userCar].vector[1]) / _parent[_root.userCar].traction;
  216.       }
  217.    }
  218. }
  219. function valetIn()
  220. {
  221.    _root.userCar = this._name;
  222.    spaceUp = false;
  223.    if(isMovable)
  224.    {
  225.       isPlayer = true;
  226.       _parent.valet_mc._visible = false;
  227.    }
  228. }
  229. function valetCheck2()
  230. {
  231.    _parent.valet_mc.block = false;
  232.    if(this.hitTest(_parent.valet_mc.hit_mc))
  233.    {
  234.       if(checkCollision(this,_parent.valet_mc) != undefined || checkCollision(this,_parent.valet_mc) != null)
  235.       {
  236.          _parent.valet_mc.block = true;
  237.       }
  238.    }
  239. }
  240. function checkHealth()
  241. {
  242.    if(health > 0)
  243.    {
  244.       this.target_mc.gotoAndStop(5 - Math.ceil(health / 25));
  245.    }
  246.    else
  247.    {
  248.       this.gotoAndStop(_totalframes);
  249.       var _loc4_ = _parent.blast_mc.attachMovie("blast","blast" + _parent.blast_mc.getNextHighestDepth(),_parent.blast_mc.getNextHighestDepth());
  250.       _loc4_._x = this._x;
  251.       _loc4_._y = this._y;
  252.       _loc4_._xscale = _loc4_._yscale = 60;
  253.       _loc4_.parent = this._name;
  254.       if(!(this._name == "car1_mc" || this._name == "car2_mc" || this._name == "car3_mc"))
  255.       {
  256.          if(this.isMovable && this._name == _root.userCar)
  257.          {
  258.             _parent.valet_mc._x = this._x;
  259.             _parent.valet_mc._y = this._y;
  260.             _root.userCar = "";
  261.             spaceUp = false;
  262.             isPlayer = false;
  263.             _parent.valet_mc.hit = false;
  264.             _parent.valet_mc._visible = true;
  265.          }
  266.          _root.score += 500;
  267.       }
  268.    }
  269. }
  270. gotoAndStop(myFrame);
  271. var scope = _parent;
  272. var tolerance = 120;
  273. if(this._name != "car1_mc" && this._name != "car2_mc" && this._name != "car3_mc")
  274. {
  275.    this._name = "Ocar" + _root.carCount++;
  276.    _root.carArray.push(this);
  277. }
  278. var accel = 0.3;
  279. var steer = 0.04;
  280. var steer_normal = 0.08;
  281. var steer_handbrake = 0.099;
  282. var steer_threshold = 4;
  283. var MINspd = -5;
  284. var MAXspd = 15;
  285. var MAXskiddisplay = 2;
  286. var MAXturnSpd = 10;
  287. var MaxTurnSkid = 18;
  288. var deccel = 0.92;
  289. var handbrake = 0.33;
  290. var handbrake_traction = 20;
  291. var drift = 0.48;
  292. if(_root.level > 5)
  293. {
  294.    drift = 0.88;
  295.    if(_root.level > 10)
  296.    {
  297.       drift = 0.38;
  298.       if(_root.level > 15)
  299.       {
  300.          drift = 0.18;
  301.       }
  302.    }
  303. }
  304. var speed = 0;
  305. var surface = 1;
  306. var traction = 2;
  307. var traction_max = 1;
  308. var vector = [0,0];
  309. var bounceBack = 0.4;
  310. var angle = this._rotation / 180 * 3.141593;
  311. var skidding = false;
  312. var turnskidding = false;
  313. var hit = false;
  314. var prevX;
  315. var prevY;
  316. var myCar;
  317. var health = 100;
  318. var isPlayer = false;
  319. var r = this._width / 2 + _parent.valet_mc._width / 2;
  320. var diag = Math.sqrt(this._width * this._width + this._height * this._height) / 2;
  321. var isPlayer = false;
  322. var spaceUp = true;
  323. var prevName = "";
  324. onEnterFrame = function()
  325. {
  326.    if(this._currentframe != _totalframes)
  327.    {
  328.       checkHealth();
  329.       if(isPlayer)
  330.       {
  331.          if(!hit)
  332.          {
  333.             move();
  334.          }
  335.       }
  336.       else
  337.       {
  338.          valetCheck();
  339.          hitCheck();
  340.       }
  341.       if(!Key.isDown(32))
  342.       {
  343.          spaceUp = true;
  344.       }
  345.    }
  346. };
  347.